﻿/*
 * Ext JS Library 2.0
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
var loginType="0";
var workState=false;
var istran=false;

var loginmenu;
var auxmenu;
var ivrmenu;
var isWorking=false;     
var isdial="N";    
var isApOrsoft="1";




Ext.onReady(function(){
    Ext.QuickTips.init();
    
   

    var colorMenu = new Ext.menu.ColorMenu({
        handler : function(cm, color){
            Ext.example.msg('Color Selected', 'You chose {0}.', color);
        }
    });
    


	var actUserID = new Ext.form.TextField({
			id:'actUserID',
			allowBlank : false,
			maxLength : 10,
			msgTarget : 'under',
			value:'agent1',
		    allowDecimals : true ,   //true
		    width : 50,
		    allowNegative : true    //true
        })        		
	var actPassword = new Ext.form.TextField({
			id:'actPassword',
			allowBlank : false,
			maxLength : 10,
			msgTarget : 'under',
			value:'aaAA1111',
			width : 70,
		    allowDecimals : true ,   //true
		    allowNegative : true    //true
        })        		
	var actStationID = new Ext.form.TextField({
			id:'actStationID',
			allowBlank : false,
			maxLength : 4,
			msgTarget : 'under',
			value:'7001',
		    width : 40,
		    allowDecimals : true ,   //true
		    allowNegative : true    //true
        })        		
    
	var actLogin = new Ext.Action({
        text: '登录',
		id:'btnAvilable',
		tooltip: {text:'登录', title:'', autoHide:true},
        handler: function(){
	  		var RetVal;
	  		CallParameters = new Object(); 
	  		CallParameters["UserID"] = Ext.getCmp("actUserID").getValue();
	  		CallParameters["Password"] = Ext.getCmp("actPassword").getValue();
	  		CallParameters["StationID"] = Ext.getCmp("actStationID").getValue();
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("1001",CallParameters);
        	if(RetVal==0){
        		alert("登录座席成功:"+RetVal);
        		document.getElementById("CallParametersShow").value = "登录座席成功:"+RetVal;
        	}else{
        		alert("登录座席失败:"+RetVal);
        		document.getElementById("CallParametersShow").value = "登录座席失败:"+RetVal;        		
        	}
        },
        iconCls: 'Avilable'
    });
    	
	var actLoginAvilable = new Ext.Action({
        text: '就绪',
		id:'btnAvilable',
		tooltip: {text:'就绪', title:'', autoHide:true},
        handler: function(){
	  		var RetVal;
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("1002",CallParameters);
        	if(RetVal==0){
        		alert("就绪成功:"+RetVal);
        	}else{
        		alert("就绪失败:"+RetVal);        		
        	}
        },
        iconCls: 'Avilable'
    });
    	
	var actAvilable = new Ext.Action({
        text: '业务结束NextCall',
		id:'btnAvilable',
		tooltip: {text:'事后处理结束，就绪', title:'', autoHide:true},
        handler: function(){
	  		var RetVal;
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("1101",CallParameters);
        	if(RetVal==0){
        		alert("业务结束NextCall成功:"+RetVal);
        	}else{
        		alert("业务结束NextCall失败:"+RetVal);        		
        	}
        },
        iconCls: 'Avilable'
    });
    	
	var actNotready = new Ext.Action({
        text: 'Notready',            
		id:"Auxmu",
        tooltip: {text:'Notready', title:'', autoHide:true},  
        handler: function(){
	  		var RetVal;	  		
	  		CallParameters = new Object(); 
	  		CallParameters["StatusReason"] = 5;       //未就绪原因 ID
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("1003",CallParameters);
        	if(RetVal==0){
        		alert("Notready成功:"+RetVal);
        	}else{
        		alert("Notready失败:"+RetVal);        		
        	}
        },
		iconCls: 'Aux'
    })
    
	var actParked = new Ext.Action({
        text: '暂放',            
		id:"Auxmu",
        tooltip: {text:'暂放', title:'', autoHide:true},  
        handler: function(){
	  		var RetVal;
	  		CallParameters = new Object(); 
	  		CallParameters["StatusReason"] = 8;       //暂放原因 ID
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("1004",CallParameters);
        	if(RetVal==0){
        		alert("暂放成功:"+RetVal);
        	}else{
        		alert("暂放失败:"+RetVal);        		
        	}
        },
		iconCls: 'Aux'
    })
    	
	var actPhoneNumber = new Ext.form.TextField({
			id:'actPhoneNumber',
			allowBlank : false,
			maxLength : 60,
			msgTarget : 'under',
			value:'84108088',
		    allowDecimals : true ,   //true
		    allowNegative : true    //true
        })        		
        		
	var actDail = new Ext.Action({
        text: '拨打',
		tooltip: {text:'拨打', title:'', autoHide:true},
		id:'actAccept',
        handler: function(){
	  		var RetVal;
	  		CallParameters = new Object(); 
	  		CallParameters["PhoneNumber"] = Ext.getCmp("actPhoneNumber").getValue();
	  		CallParameters["CallDialType"] = 1;  //表示(暂时定义)  0:<默认> 内线   1:AOD_1 外线  2:ACD_1 回访
	  		CallParameters["ServiceId"] = 1;
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2001",CallParameters);  
        	if(RetVal==0){
        		alert("拨打成功:"+RetVal);
        	}else{
        		alert("拨打失败:"+RetVal);        		
        	}
        },
        iconCls: 'Accept'
    });
    	
	var actRealse = new Ext.Action({
        text: '挂断',
		tooltip: {text:'挂断', title:'', autoHide:true},
		id:'actRealse',
        handler: function(){
	  		var RetVal;
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2003",CallParameters); 
        	if(RetVal==0){
        		alert("挂断成功:"+RetVal);
        	}else{
        		alert("挂断失败:"+RetVal);        		
        	}
        },
        iconCls: 'Realse'
    });
    	
    var CallFunctionToolbar = new Ext.Toolbar();
    CallFunctionToolbar.render('toolbar');
    CallFunctionToolbar.add(
    	actUserID,
    	actPassword,
    	actStationID,
		actLogin, 
		actLoginAvilable,
		 '-',
		 '-',
        actNotready,
        actParked,
		'-',
		'-',
		actPhoneNumber,
		actDail,
		actRealse,
		actAvilable,		
		'-'
		);
	
	var actHold = new Ext.Action({
        text: '保持',
		tooltip: {text:'保持', title:'', autoHide:true},
		id:'actHold',
        handler: function(){
	  		var RetVal;        
			if(document.all.HoldFlg.value=="1")
			{
				RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2004",CallParameters);
	        	if(RetVal==0){
	        		alert("保持电话开始成功:"+RetVal);
	        		document.all.HoldFlg.value = '0'
	        	}else{
	        		alert("保持电话开始失败:"+RetVal);        		
	        	}
			}
			else
			{
				RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2005",CallParameters);
	        	if(RetVal==0){
	        		alert("保持电话结束成功:"+RetVal);
	        		document.all.HoldFlg.value = '1'
	        	}else{
	        		alert("保持电话结束失败:"+RetVal);        		
	        	}
			}
        },
        iconCls: 'Hold'
    });
    	
	var actTransfer = new Ext.Action({
	    text: '二步 转接:联系',
		tooltip: {text:'二步 转接:联系', title:'', autoHide:true},
		id:'actRealse',
	    handler: function(){
	  		var RetVal;
	  		CallParameters = new Object(); 
	  		CallParameters["PhoneNumber"] = Ext.getCmp("actPhoneNumber").getValue();
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2006",CallParameters);  
	    	if(RetVal==0){
	    		alert("二步 转接:接通成功:"+RetVal);
	    		document.all.TransferConferenceFlg.value="1"
	    	}else{
	    		alert("二步 转接:接通失败:"+RetVal);        		
	    	}
	    },
		iconCls: 'Transfer'
	});
    	
	var actConference = new Ext.Action({
        text: '二步 会议:联系',
		tooltip: {text:'二步 会议:联系', title:'', autoHide:true},
		id:'actRealse',
        handler: function(){
	  		var RetVal;
	  		CallParameters = new Object(); 
	  		CallParameters["PhoneNumber"] = Ext.getCmp("actPhoneNumber").getValue();
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2009",CallParameters);  
        	if(RetVal==0){
        		alert("二步 会议:接通成功:"+RetVal);
				document.all.TransferConferenceFlg.value="2"
        	}else{
        		alert("二步 会议:接通失败:"+RetVal);        		
        	}
        },
		iconCls: 'Conference'
    });
    	
	var actCancel = new Ext.Action({
        text: '取消',            
        tooltip: {text:'取消转接或会议', title:'', autoHide:true},  
		id:'actCancel',
		handler: function(){
	  		var RetVal;    
	  		RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2008",CallParameters);
			if(document.all.TransferConferenceFlg.value=="1")
			{
	        	if(RetVal==0){
	        		alert("二步 转接:取消成功:"+RetVal);
	        	}else{
	        		alert("二步 转接:取消失败:"+RetVal);        		
	        	}
			}
			else
			{
	        	if(RetVal==0){
	        		alert("二步 会议:取消成功:"+RetVal);
	        	}else{
	        		alert("二步 会议:取消失败:"+RetVal);        		
	        	}
			}
		},
		iconCls: 'Cancel'
        
    });

	var actComplete = new Ext.Action({
        text: '确定',            
        tooltip: {text:'确定转接或会议', title:'', autoHide:true},  
		id:'actComplete',
		handler: function(){
	  		var RetVal;
			if(document.all.TransferConferenceFlg.value=="1")
			{
				RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2007",CallParameters);
	        	if(RetVal==0){
	        		alert("二步 转接:确定成功:"+RetVal);
	        	}else{
	        		alert("二步 转接:确定失败:"+RetVal);        		
	        	}
			}
			else
			{
				RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2010",CallParameters);
	        	if(RetVal==0){
	        		alert("二步 会议:确定成功:"+RetVal);
	        	}else{
	        		alert("二步 会议:确定失败:"+RetVal);        		
	        	}
			}
		},
		iconCls: 'Complete'
    });


	var actSeqNumber = new Ext.form.TextField({
			id:'actSeqNumber',
			allowBlank : false,
			maxLength : 10,
			msgTarget : 'under',
			//value:'',
		    allowDecimals : true ,   //true
		    width : 100,
		    allowNegative : true    //true
        })        		
	var actFileName = new Ext.form.TextField({
			id:'actFileName',
			allowBlank : false,
			maxLength : 10,
			msgTarget : 'under',
			//value:'',
			width : 200,
		    allowDecimals : true ,   //true
		    allowNegative : true    //true
        })        		
	var actPlay = new Ext.Action({
        text: '录音播放',
		tooltip: {text:'录音播放', title:'', autoHide:true},
		id:'actPlay',
        handler: function(){
	  		var RetVal;
	  		CallParameters = new Object(); 
	  		CallParameters["SeqNumber"] = Ext.getCmp("actSeqNumber").getValue();
	  		CallParameters["FileName"] = Ext.getCmp("actFileName").getValue();
	  		CallParameters["Rate"] = 1;  //播放录音的速度
			RetVal = document.SoftPhoneOCX.SoftPhoneFunction("2020",CallParameters);  
        	if(RetVal==0){
        		alert("成功:"+RetVal);
				document.all.TransferConferenceFlg.value="2"
        	}else{
        		alert("失败:"+RetVal);        		
        	}
        },
		iconCls: 'Avilable'
    });



    var CallFunctionToolbar1 = new Ext.Toolbar();
    CallFunctionToolbar1.render('toolbar');
    CallFunctionToolbar1.add(
    	actHold,
		'-',
		'-',
		'-',
		'-',
		actTransfer,
		actConference,
		actCancel,
		actComplete,    	
		/*
		'-',
		'-',
		actSeqNumber,
		actFileName,
		actPlay,
		*/
		'-'
		);

});


    //*****************************************************************************************************************
